#include "stdafx.h"
#include "./light.h"

float Light::s_ambientLight[] = { 1.f, 0.f, 0.f, 1.0f};
float Light::s_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f};

Light::Light()
{

}

Light::~Light()
{
	ShutDownLights();
}

void Light::ShutDownLights()
{
	glDisable(GL_LIGHT0);
	glDisable(GL_LIGHT1);
	glDisable(GL_LIGHT2);
	glDisable(GL_LIGHT3);
	glDisable(GL_LIGHT4);
}

// Light values and coordinates
GLfloat	 lightPos0[] = { 50.0f, 50.0f, 75.0f, 1.0f };
GLfloat  specular0[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat  specref0[] =  { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat  ambientLight0[] = { 1.f, 0.1f, 0.1f, 1.0f};
GLfloat  spotDir0[] = { 0.0f, 0.0f, -1.0f, 1.};

// Light values and coordinates
GLfloat	 lightPos1[] = { 100.0f, 100.0f, 50.0f, 1.0f };
GLfloat  specular1[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat  specref1[] =  { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat  ambientLight1[] = { 1.f, 1.f, 0.f, 1.f};
GLfloat  spotDir1[] = { 0.0f, 0.0f, -1.0f, 1. };

// Light values and coordinates
GLfloat	 lightPos2[] = { 0.0f, 0.0f, 50.0f, 1.0f };
GLfloat  specular2[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat  specref2[] =  { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat  ambientLight2[] = { 1.f, 1.f, 0.f, 1.f};
GLfloat  spotDir2[] = { 0.0f, 0.0f, -1.0f, 1. };

// Light values and coordinates
GLfloat	 lightPos3[] = { 100.0f, 0.0f, 50.0f, 1.0f };
GLfloat  specular3[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat  specref3[] =  { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat  ambientLight3[] = { 1.f, 0.f, 1.f, 1.f};
GLfloat  spotDir3[] = { 0.0f, 0.0f, -1.0f, 1. };

// Light values and coordinates
GLfloat	 lightPos4[] = { 0.0f, 100.0f, 50.0f, 1.0f };
GLfloat  specular4[] = { 1.0f, 1.0f, 1.0f, 1.0f};
GLfloat  specref4[] =  { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat  ambientLight4[] = { 1.f, 0.f, 1.f, 1.f};
GLfloat  spotDir4[] = { 0.0f, 0.0f, -1.0f, 1. };

//hard code
void Light::SetLights()
{
	//for (int i = 0; i < 7; ++i)
	//{
	//	if (i >= m_pFile->nlights)
	//	{
	//		break;
	//	}
	//	SetLight(GL_LIGHT0 + i, m_pFile->lights[i]);
	//}

	//GL_LIGHT0
	glLightfv(GL_LIGHT0, GL_DIFFUSE, ambientLight0);
	glLightfv(GL_LIGHT0, GL_SPECULAR, specular0);

	glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.);
	glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 20);

	glLightfv(GL_LIGHT0,GL_POSITION, lightPos0);
	glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION, spotDir0);

	glEnable(GL_LIGHT0);

	float exponent = 8.5f;

	//GL_LIGHT1
	glLightfv(GL_LIGHT1, GL_DIFFUSE, ambientLight1);
	glLightfv(GL_LIGHT1, GL_SPECULAR, specular1);

	glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 90);
	glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, exponent);

	glLightfv(GL_LIGHT1,GL_POSITION, lightPos1);
	glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION, spotDir1);

	glEnable(GL_LIGHT1);

	//GL_LIGHT2
	glLightfv(GL_LIGHT2, GL_DIFFUSE, ambientLight2);
	glLightfv(GL_LIGHT2, GL_SPECULAR, specular2);

	glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 90);
	glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, exponent);

	glLightfv(GL_LIGHT2,GL_POSITION, lightPos2);
	glLightfv(GL_LIGHT2,GL_SPOT_DIRECTION, spotDir2);

	glEnable(GL_LIGHT2);

	//GL_LIGHT3
	glLightfv(GL_LIGHT3, GL_DIFFUSE, ambientLight3);
	glLightfv(GL_LIGHT3, GL_SPECULAR, specular3);

	glLightf(GL_LIGHT3, GL_SPOT_CUTOFF, 90);
	glLightf(GL_LIGHT3, GL_SPOT_EXPONENT, exponent);

	glLightfv(GL_LIGHT3,GL_POSITION, lightPos3);
	glLightfv(GL_LIGHT3,GL_SPOT_DIRECTION, spotDir3);

	glEnable(GL_LIGHT3);

	//GL_LIGHT4
	glLightfv(GL_LIGHT4, GL_DIFFUSE, ambientLight4);
	glLightfv(GL_LIGHT4, GL_SPECULAR, specular4);

	glLightf(GL_LIGHT4, GL_SPOT_CUTOFF, 90);
	glLightf(GL_LIGHT4, GL_SPOT_EXPONENT, exponent);

	glLightfv(GL_LIGHT4,GL_POSITION, lightPos4);
	glLightfv(GL_LIGHT4,GL_SPOT_DIRECTION, spotDir4);

	glEnable(GL_LIGHT4);

	glDisable(GL_LIGHT5);
	glDisable(GL_LIGHT6);
	glDisable(GL_LIGHT7);
}

void Light::SetVerticalLight(unsigned int light, float pos[3])
{
	glLightfv(light, GL_DIFFUSE, s_ambientLight);
	glLightfv(light, GL_SPECULAR, s_specular);

	glLightf(light, GL_SPOT_CUTOFF, 45);
	glLightf(light, GL_SPOT_EXPONENT, 30);

	float lightPos[4] = {pos[0], pos[1], 30., 1.};
	glLightfv(light,GL_POSITION, lightPos);

	float spotDir[4] = {0., 0., -1., 1.};
	glLightfv(light,GL_SPOT_DIRECTION, spotDir);

	glEnable(light);
}

//void Light::SetLight(unsigned int light, Lib3dsLight* p3dsLight)
//{
//	//glLightfv(light, GL_AMBIENT, p3dsLight->color);
//	glLightfv(light, GL_DIFFUSE, p3dsLight->color);
//	glLightfv(light, GL_SPECULAR, p3dsLight->color);
//
//	glLightf(light, GL_SPOT_CUTOFF, p3dsLight->hotspot);
//	glLightf(light, GL_SPOT_EXPONENT, 0.);
//	//glLightf(light, GL_SPOT_EXPONENT, p3dsLight->falloff);
//
//	if (light != GL_LIGHT0)
//	{
//		float pos[4] = {60., 60., 10., 1.};
//		float target[4] = {-pos[0], -pos[1], -pos[2], 1.};
//
//		glLightfv(light, GL_POSITION, pos);
//		glLightfv(light, GL_SPOT_DIRECTION, target);
//	}
//	else
//	{
//		glLightfv(light, GL_POSITION, p3dsLight->position);
//		glLightfv(light, GL_SPOT_DIRECTION, p3dsLight->target);
//	}
//
//	glEnable(light);
//}